package czy.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/*
 * swagger配置，主要配置了Docket(案卷)，ApiInfo(api 信息)
 * swagger文档JSON信息rest接口/v2/api-docs
 * swagger文档页面swagger-ui
 */
@Configuration
@EnableSwagger2
public class SpringSwaggerConfig {

    @Configuration
    public class Swagger21 {

        @Bean
        public Docket createRestApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .groupName("redis-admin")
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("czy.demo.controller"))
                    .paths(PathSelectors.any())
                    .build();
        }

        /* API信息 */
        private ApiInfo apiInfo() {

            Contact contact = new Contact("crayon-shin-chan","https://github.com/crayon-shin-chan","1253665625@qq.com");

            return new ApiInfoBuilder()
                    /* API标题 */
                    .title("swagger构建api文档")
                    /* API描述 */
                    .description("简单优雅的restfun风格")
                    /* 作者联系方式？ */
                    .termsOfServiceUrl("https://blog.csdn.net/qq_27868061")
                    /* 版本 */
                    .version("1.0")
                    /* 许可 */
                    .license("Apache License")
                    .contact(contact)
                    .build();
        }
    }
}
